-- stone_box
-- created by panyl
-- 地牢格子：隐蔽的石匣

return {
    -- 自动战斗
    autoFight = function(grid)
        local dbase = DungeonM.queryElement(grid.element, "dbase");
        -- 判断是否显示该格子
        local function isShow()
            local dbase = DungeonM.queryElement(grid.element, "dbase");
            if type(dbase) == "table" then
                -- 如果配置了需要道具才出现，需要判断一下包裹中是否有相应的道具
                if type(dbase["need_property"]) == "number"  then
                    if ItemM.getAmount(ME.user, dbase["need_property"]) > 0 then
                        return true;
                    end
                elseif type(dbase["need_property"]) == "table" then
                    for _, classId in pairs(dbase["need_property"]) do
                        if ItemM.getAmount(ME.user, classId) > 0 then
                            return true;
                        end
                    end
                end
            end
        end

        if not isShow() then
            return false;
        end

        local pos = grid:getPos();
        return DungeonActionM.go("do_building_bonus", pos);
    end,
};
